/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package siac.com.dao;

import java.util.List;

import org.hibernate.Session;

/**
 * @author Domingos Razao Fancone
 * 
 * @param <T>
 */
public abstract class AbstractHibernateDao<T> {
	private Class<T> entityClass;

	/**
	 * @param entityClass
	 */
	public AbstractHibernateDao(Class<T> entityClass) {
		this.entityClass = entityClass;
	}

	protected abstract Session getSession();

	public void saveOrUpdate(T entity) {
		getSession().saveOrUpdate(entity);
	}

	public void create(T entity) {
		getSession().save(entity);
	}

	public void edit(T entity) {
		getSession().update(entity);
	}

	public void remove(T entity) {
		getSession().delete(entity);
	}

	public T find(Long id) {
		return (T)getSession().get(entityClass, id);
	}

	public List<T> findAll() {
		return (List<T>)getSession().createCriteria(entityClass).list();
	}

}